@isTest
private class PriceListControllerTest {
    static testMethod void testMethod1() {
        Account acc = TestUtils.createAccount();
        acc.Level__c = '一级医院';
        insert acc;
        
        ProductStructure__c ps = new ProductStructure__c();
        ps.Classify3__c = '试剂';
        insert ps;
        Product__c p1 = TestUtils.createProduct();
        p1.Category0__c = '试剂';
        p1.ProductStructure__c = ps.Id;
        p1.PriceCompany__c = 'MKSY';
        p1.NCCode__c = '000001';
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        
        Product__c p2 = TestUtils.createProduct();
        p2.Category0__c = '试剂';
        p2.ProductStructure__c = ps.Id;
        p2.PriceCompany__c = 'MKSY';
        p2.NCCode__c = '000002';
        p2.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        insert new Product__c[] {p1, p2};
  
        Price__c pr1 = new Price__c(
            Product__c = p1.Id,
            Company__c = '四川省迈克实业有限公司',
            CompanyBottomPrice__c = 1.0,
            HospitalBottomPrice__c = 1.0,
            InvoiceDealerPrice__c = 1.0,
            AreaDealerPrice__c = 1.0,
            MarketPrice__c = 1.0,
            HospitalManagerPrice__c= 1.0,
            InstCost__c = 0.5
            
        );
        Price__c pr2 = new Price__c(
            Product__c = p2.Id,
            Company__c = '四川省迈克实业有限公司',
            CompanyBottomPrice__c = 2.0,
            HospitalBottomPrice__c = 1.0,
            InvoiceDealerPrice__c = 2.0,
            AreaDealerPrice__c = 1.0,
            MarketPrice__c = 1.0,
            HospitalManagerPrice__c= 1.0,
            InstCost__c = 0.5
            
        );
        insert new Price__c[] {pr1,pr2};
        
           /// 日期处理
        Integer m = Date.today().month(); //当前月份
        Integer y = Date.today().year();  //当前年份 
       ///取上月
         if(m == 1){
        m = 12 ;
            y -= 1;
        }else{
        m -= 1;
            
        }
        
        String  month = String.valueOf(m) + '月';
        String  year= String.valueOf(y) + '年';
        AveragePrice__c av1 = new AveragePrice__c(
        Product__c = p1.Id,
            Company__c = '四川省迈克实业有限公司',
            AveragePrice__c = 1.0,
            Year__c = year,
            Month__c = month,
            PriceProvince__c = '四川省/西藏'
            
        );
          AveragePrice__c av2 = new AveragePrice__c(
        Product__c = p2.Id,
            Company__c = '四川省迈克实业有限公司',
            AveragePrice__c = 1.0,
            Year__c = year,
            Month__c = month,
            PriceProvince__c = '四川省/西藏'
            
        );
        insert new AveragePrice__c[] {av2,av1}; 


        PriceList__c pl = new PriceList__c();
        pl.Product__c = p1.Id;
        pl.SalesCode__c = '05';
        pl.Price__c = 100;
        pl.Account__c = acc.Id;
        pl.Company__c = '四川省迈克实业有限公司';
        pl.ApplicableCustomers__c = acc.Id;

        insert pl;

        AdjustPrice__c ap = new AdjustPrice__c();
        ap.Account__c = acc.Id;
        ap.Company__c = '四川省迈克实业有限公司';
        ap.ApplicableCustomers__c = acc.Id;
        ap.SalesCode__c = '05';

        insert ap;

        AdjustPriceProduct__c app = new AdjustPriceProduct__c();
        app.AdjustPrice__c = ap.Id;
        app.Product__c = p1.Id;
        app.OriginalPrice__c = 1;
        app.AdjustSalesPrice__c = 2;
        insert app;


        PriceListController prc = new PriceListController(new ApexPages.StandardController(ap));
        prc.init();
        prc.accId = acc.Id;
		
        prc.init();
        prc.adjustId = ap.Id;
        prc.init();

        prc.getDetails();
        prc.setNil();
        prc.getProduct();
        prc.setNil();
        prc.getProductFromPriceList(acc.Id, false);

        prc.searchJson =EncodingUtil.urlEncode('{"type":"FromProduct","brand":"","spec":"","cate0":"","cate1":"","nccode":"","ptype":"","serialNo":""}', 'UTF-8') ;

        prc.search();

        List<PriceListController.AdjustPriceBean> resList = new List<PriceListController.AdjustPriceBean>(); 

        PriceListController.AdjustPriceBean ajst = new PriceListController.AdjustPriceBean(p2,pr2,av2,new PriceList__c(),new PriceList__c(),false);
        
        resList.add(ajst);
    	prc.resJson = EncodingUtil.urlEncode(JSON.serialize(resList), 'UTF-8');

    	prc.save();







    }
}